package com.jiepu.homework.module5.exercise5;

public class CheckingAccount extends Account { // 信用卡

	private double overdraft; // 透支额度

	public CheckingAccount(double balance, double overdraft) {
		super(balance);
		this.overdraft = overdraft;
	}

	public CheckingAccount(double balance) {
		this(balance, 0);
	}

	@Override
	public boolean withdraw(double amount) {

		if (amount > balance + overdraft) {
			System.out.println("余额加透支额度总额不足，取款失败！");
			return false;
		}
		
		if (amount <= balance) {
			// 如果余额部分够用，直接减去对应的数额，透支额度无需影响
			balance -= amount;
		} else {
			// 如果余额不够用，扣光余额，剩余不足部分从透支额度中扣除
			overdraft -= (amount - balance);
			balance = 0;
		}
		return true;
	}
	
	public double getOverdraft() {	// 查询透支额度
		return this.overdraft;
	}
	
	

}
